﻿// Developer Express Code Central Example:
// World Wide CRM Demo
// 
// The World Wide CRM demo is a next generation application with outstanding
// navigation capabilities and shows a reimagined view of customer contact and
// management. This demo showcases many of the most popular features of the
// WinForms Subscription.
// 
// You can find sample updates and versions for different programming languages here:
// http://www.devexpress.com/example=E3993

using System.ComponentModel;
using System;
using DevExpress.CrmDemo.Win.Helpers;

namespace DevExpress.CrmDemo.Win.Data {
    public enum Stage {
        Lead, Qualification, NeedsAnalysis, Proposed, Negotiation, Closed, Cancelled
    }

    public class Opportunity : INotifyPropertyChanged {

        #region Public members
        public int ID {
            get { return _id; }
            set {
                _id = value;
                InvokePropertyChanged("ID");
            }
        }

        public string Name {
            get { return _name; }
            set {
                _name = value;
                InvokePropertyChanged("Name");
            }
        }

        public string AccountName {
            get { return _accountName; }
            set {
                _accountName = value;
                InvokePropertyChanged("AccountName");
            }
        }

        public int OwnerId {
            get { return _ownerId; }
            set {
                _ownerId = value;
                InvokePropertyChanged("OwnerId");
            }
        }

        public string Technology {
            get { return _technology; }
            set {
                _technology = value;
                InvokePropertyChanged("Technology");
            }
        }

        public int? CostSize {
            get { return _costSize; }
            set {
                _costSize = value;
                InvokePropertyChanged("CostSize");
            }
        }

        public decimal? ProbabilityPercent {
            get { return _probabilityPercent; }
            set {
                _probabilityPercent = value;
                InvokePropertyChanged("ProbabilityPercent");
            }
        }

        public Stage Stage {
            get { return _stage; }
            set {
                _stage = value;
                InvokePropertyChanged("Stage");
            }
        }

        public string Description {
            get { return _description; }
            set {
                _description = value;
                InvokePropertyChanged("Description");
            }
        }

        public DateTime CreatedDate {
            get { return _createdDate; }
            set {
                _createdDate = value;
                InvokePropertyChanged("CreatedDate");
            }
        }

        public DateTime? CloseDate {
            get { return _closeDate; }
            set {
                _closeDate = value;
                InvokePropertyChanged("CloseDate");
            }
        }

        public int? Weeks {
            get { return _weeks; }
            set {
                _weeks = value;
                InvokePropertyChanged("Weeks");
            }
        }

        public int? TeamSize {
            get { return _teamSize; }
            set {
                _teamSize = value;
                InvokePropertyChanged("TeamSize");
            }
        }

        public int? Revenue {
            get { return _revenue; }
            set {
                _revenue = value;
                InvokePropertyChanged("Revenue");
            }
        }

        public string AccountOwnerName {
            get { return _accountOwnerName; }
            set {
                _accountOwnerName = value;
                InvokePropertyChanged("AccountOwnerName");
            }
        }

        public string AccountOwnerPhone {
            get { return _accountOwnerPhone; }
            set {
                _accountOwnerPhone = value;
                InvokePropertyChanged("AccountOwnerPhone");
            }
        }

        public string AccountOwnerEmail {
            get { return _accountOwnerEmail; }
            set {
                _accountOwnerEmail = value;
                InvokePropertyChanged("AccountOwnerEmail");
            }
        }

        public string AccountOwnerRole {
            get { return _accountOwnerRole; }
            set {
                _accountOwnerRole = value;
                InvokePropertyChanged("AccountOwnerRole");
            }
        }

        public string NextStep {
            get { return _nextStep; }
            set {
                _nextStep = value;
                InvokePropertyChanged("NextStep");
            }
        }

        private ActivityList activities = new ActivityList();

        public ActivityList Activities {
            get { return activities; }
            set { activities = value; }
        }

        public string OpportunityType {
            get { return _opportunityType; }
            set {
                _opportunityType = value;
                InvokePropertyChanged("OpportunityType");
            }
        }

        public string LeadSource {
            get { return _leadSource; }
            set {
                _leadSource = value;
                InvokePropertyChanged("LeadSource");
            }
        }

        public string AgeText {
            get { return (DateTime.Now - this.CreatedDate).GetRelativeTimeString(); }
        }

        #endregion

        #region INotifyPropertyChanged implementation
        public event PropertyChangedEventHandler PropertyChanged;

        private void InvokePropertyChanged(string name) {
            PropertyChangedEventHandler handler = PropertyChanged;
            if(handler != null) handler(this, new PropertyChangedEventArgs(name));
        }
        #endregion

        #region Private data
        private int _id;
        private string _name;
        private string _accountName;
        private int _ownerId;
        private string _technology;
        private int? _costSize;
        private decimal? _probabilityPercent;
        private Stage _stage;
        private string _description;
        private DateTime _createdDate;
        private DateTime? _closeDate;
        private int? _teamSize;
        private int? _weeks;
        private int? _revenue;
        private string _accountOwnerName;
        private string _accountOwnerPhone;
        private string _accountOwnerEmail;
        private string _accountOwnerRole;
        private string _nextStep;
        private string _opportunityType;
        private string _leadSource;
        #endregion

    }

    public class OpportunityList : BindingList<Opportunity> { }
}